<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>饮食记录列表</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #4CAF50;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        a {
            color: #4CAF50;
            text-decoration: none;
            margin-right: 10px;
        }
        a:hover {
            text-decoration: underline;
        }
        .search-container {
            margin: 20px 0;
        }
        .search-container input {
            padding: 8px;
            width: 300px;
        }
        .search-container button {
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        .search-container button:hover {
            background-color: #45a049;
        }
        .add-btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            margin-bottom: 10px;
        }
        .add-btn:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<h2>饮食记录列表</h2>

<!-- 搜索栏 -->
<div class="search-container">
    <form action="${pageContext.request.contextPath}/dietrecord/list" method="get">
        <input type="text" name="searchKey" placeholder="输入用户ID、日期等">
        <button type="submit">搜索</button>
        <a class="add-btn" href="${pageContext.request.contextPath}/dietrecord/add">添加记录</a>
    </form>
</div>

<table>
    <tr>
        <th>ID</th>
        <th>用户</th>
        <th>食物</th>
        <th>用餐时间</th>
        <th>份数</th>
        <th>总热量</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    <c:forEach var="dietRecord" items="${dietRecords}">
        <tr>
            <td>${dietRecord.dietrecordid}</td>
            <td>${dietRecord.user.userid}</td>
            <td>${dietRecord.foodsrecipe.recipeid}</td>
            <td>${dietRecord.eattime}</td>
            <td>${dietRecord.num}</td>
            <td>${dietRecord.totalcalories}</td>
            <td>${dietRecord.createtime}</td>
            <td>
                <a href="${pageContext.request.contextPath}/dietrecord/update/${dietRecord.dietrecordid}">编辑</a>
                <a href="${pageContext.request.contextPath}/dietrecord/delete/${dietRecord.dietrecordid}"
                   onclick="return confirm('确定删除这条饮食记录吗？')">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
</body>
</html>